package com.walterweimod.auxiliary_attributes.mixin;

import com.walterweimod.auxiliary_attributes.event.hooks.ModForgeHooks;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static com.walterweimod.auxiliary_attributes.Auxiliary_attributes.*;

@Mixin(Player.class)
public class LivingAfterDamageMixin {
    static {
        System.out.println("LivingAfterDamageMixin loaded!");
    }

    @Inject(method = "actuallyHurt(Lnet/minecraft/world/damagesource/DamageSource;F)V",
            at = @At("TAIL"))
    private void actuallyHurt(DamageSource p_21240_, float p_21241_, CallbackInfo callbackInfo){
        LivingEntity livingEntity = (LivingEntity) ((Object) this);

        if (!livingEntity.isInvulnerableTo(p_21240_)){
            getLogger().info("触发LivingAfterDamageEvent!!!");

            ModForgeHooks.afterLivingDamage(livingEntity, p_21240_, p_21241_);

            getLogger().info("已完成LivingAfterDamageEvent!!!");
        }
    }
}
